package com.doushu.dispatch.mapper;

import com.doushu.dispatch.entity.Item;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ItemMapper {

//    @Select({
//            "<script>"
//                    + "INSERT INTO ds_items(itemid,sid,title,itemdetailurl,imgurl,price,create_time) VALUES"
//                    + "<foreach collection='list' item='item' separator=','>"
//                    + "(#{item.itemId},#{item.sid},#{item.title},#{item.itemDetailUrl},#{item.imgUrl},#{item.price},#{item.createTime})"
//                    + "</foreach>"
//                    + "</script>"
//    })
//    Integer insertItems(List<Item> items);

    @Insert("INSERT INTO ds_items(itemid,sid,title,itemdetailurl,imgurl,price,create_time) VALUES (#{itemId},#{sid},#{title},#{itemDetailUrl},#{imgUrl},#{price},#{createTime})")
    Integer insertItem(Item item);

    @Update("UPDATE ds_items SET "
            + "sid=#{sid},"
            + "title=#{title},"
            + "itemdetailurl=#{itemDetailUrl},"
            + "imgurl=#{imgUrl},"
            + "price=#{price},"
            + "create_time=#{createTime} "
            + "WHERE itemid=#{itemId}")
    void updateItem(Item item);

    @Select({"SELECT 1 FROM ds_items WHERE sid=#{sid} limit 1"})
    Boolean existsBySid(Long sid);

    @Select({"SELECT itemid FROM ds_items WHERE sid=#{sid} AND status=#{status}"})
    List<Long> findItemIdsBySidAndStatus(@Param("sid") Long sid,@Param("status") Boolean status);
}
